//
//  JSMDreamCityDetailsRouteViewController.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/2.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDreamCityDetailsRouteViewController.h"
#import "JSMDreamCitySpecialTravelModel.h"
#import "JSMDreamCitySpecialTravelTableViewCell.h"

@interface JSMDreamCityDetailsRouteViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong) UITableView *routeDetailsTableView;

@end

@implementation JSMDreamCityDetailsRouteViewController

#pragma mark - Method viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"路线详情";
    
    self.routeDetailsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT) style:UITableViewStylePlain];
    self.routeDetailsTableView.bounces = NO;
    self.routeDetailsTableView.dataSource = self;
    _routeDetailsTableView.delegate = self;
    _routeDetailsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_routeDetailsTableView registerClass:[JSMDreamCitySpecialTravelTableViewCell class] forCellReuseIdentifier:@"reuse"];
    [self.view addSubview:self.routeDetailsTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Method 返回分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dreamCitySpecialTravelArray.count;
}
#pragma mark - Method 每个分区title名字
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    JSMDreamCitySpecialTravelModel *temp = self.dreamCitySpecialTravelArray[section];
    return [NSString stringWithFormat:@"第%ld天", temp.dayNum];
}
#pragma mark - Method 每个分区返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
#pragma mark - Method 每个分区行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    JSMDreamCitySpecialTravelModel *temp = self.dreamCitySpecialTravelArray[indexPath.section];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
    CGRect rect = [temp.travelSights boundingRectWithSize:CGSizeMake(SCREENWIDTH, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
#pragma mark - Method cell样式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    JSMDreamCitySpecialTravelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    JSMDreamCitySpecialTravelModel *temp = self.dreamCitySpecialTravelArray[indexPath.section];
    cell.travelSightsLabel.text = temp.travelSights;
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    return cell;
}

@end
